#!/bin/zsh

running_os=$(sw_vers -ProductVersion | cut -d "." -f 1)

if [ $running_os -lt 13 ]
then
	exit 0
fi

############## Define variables ###############
# Do we just need to confirm one profile or all
# Set as an environment variable

# Default values
found_quantity=0
found_profile=""
bold=$(tput bold)
regular=$(tput sgr0)

# Runtime
to_find=$#

############## Script Start #############

echo "Set to match all or one Profile IDs: ${bold}${all_or_one}${regular}"

while [ $# -gt 0 ]
do
	echo ""
	echo "Looking for profile: ${bold}$1${regular}"

	found_profile=$(profiles list all | awk -v search=$1  '$0 ~ search {print $NF}')

#	echo "Found: $found_profile"

	if [ -z "$found_profile" ]
	then
		echo "Profile found: ${bold}FALSE${regular}"
	fi


	if [ ! -z $found_profile ]
	then
		case "$all_or_one" in

			"one")
				echo "Set to match one profile ID"
				echo "Found a profile from list: $found_profile"
				exit 0
			;;
			"all")
				echo "Profile found: ${bold}TRUE${regular}"
				found_quantity=$(( $found_quantity + 1 ))				
			;;
			*)
				echo "Unexpected search"
				exit 1
			;;
		esac
	fi

	shift
done

if [ $found_quantity -ne $to_find ]
then
	echo "Only found $found_quantity profiles from the supplied list of $to_find"
	exit 1
fi

echo "All profiles found.  Exiting 0"
 
exit 0
